import type { App } from "vue";
import { createRouter, createWebHistory } from "vue-router";
import { constantRoutes } from "./routes";

/**
 * 创建路由
 */
const router = createRouter({
  history: createWebHistory(),
  routes: constantRoutes,
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

/**
 * 重置路由
 */
export function resetRouter() {
  router.replace({ path: "/login" });
  window.location.reload();
}

export const setupRouter = (app: App) => {
  app.use(router);
};

export default router;
